import request from '../request';
import qs from "qs"

export const loginApi = (params: ILoginParms): RSP<ILoginResponse> =>
  request.post("/admin/login", params);

export const userInfoApi = (): RSP<IUserInfoResponse> => request.get("admin/info");

export const getUserListApi = (params?: IUserListParams): RSP<IUserListData<IUserModel>> => request.get("/admin/list", { params });

export const updateUserStatusApi = (params: IUpdateUserStatusParams): Promise<IResponse<any>> => request.post(`/admin/updateStatus/${params.id}?status=${params.status}`)

// 注册用户的接口
export const registerUserApi = (params: IRegisterUserParams): RSP<IUserModel> =>
  request.post("/admin/register", params);

export const getUserInfoApi = (id: number): RSP<IUserModel> =>
  request.get(`/admin/${id}`);

// 修改用户信息的接口
export const updateUserInfoApi = (params: IUserModel): RSP<any> =>
  request.post(`/admin/update/${params.id}`, params);

export const getRoleListApi = (): RSP<IRoleModel[]> =>
  request.get("/role/listAll");

export const getRoleListByAdminIdApi = (adminId: number): RSP<IRoleModel[]> =>
  request.get(`/admin/role/${adminId}`);

export const updateRolesApi = (params: IUpdateRolesParams) => {
  return request.post(
    `/admin/role/update?${qs.stringify(params, { arrayFormat: "comma" })}`
  );
};

// 分页获取 角色列表
export const queryRoleListApi = (
  params: IUserListParams
): RSP<IUserListData<IRoleModel>> => request.get("/role/list", { params });

export const getAllResourceApi = (): RSP<IResourceModel[]> => request.get("/resource/listAll")

export const getAllResourceCategoryApi = (): RSP<IResourceCategoryModel[]> =>
request.get("/resourceCategory/listAll");

export const getListRoleResourceApio = (
  roleId: number
): RSP<IResourceModel[]> => request.get(`/role/listResource/${roleId}`);

export const allocResourceApi = (params: IAllocResourceParams): RSP<any> =>
  request.post(
    "/role/allocResource?" + qs.stringify(params, { arrayFormat: "comma" })
  );